/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.engine.translate;

import com.engine.knowledge.Master;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
import com.wolfram.alpha.WAEngine;
import com.wolfram.alpha.WAQuery;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Giank
 */
public class Translator {
    
    public String appId;
    private String secret;
    
    private final static Logger LOG = Logger.getLogger(Translator.class .getName()); 
    
    public Translator(){
        loadProperties();
        
        // Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
        Translate.setClientId(appId);
        Translate.setClientSecret(secret);
    }
    
    /**
     * Load main properties for knowledge acquisition
     */
    private void loadProperties(){
        // Read properties file.
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream("src/main/resources/configuration.properties"));
            this.appId = properties.getProperty("appId");
            this.secret  = properties.getProperty("secret");
        } catch (IOException e) {
            LOG.log(Level.SEVERE, "Error reading the configuration.properties file");
        }
    }
    
    /**
     * Translates a given input from origin language to destination language
     * @param input         Message
     * @param origin        Language origin
     * @param destination   Target language
     * @return              Message translated to target language
     */
    public String translate(String input, Language origin, Language destination){
        String response = input;
        try {
            response = Translate.execute(input, origin, destination);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, "Exception Translator.translate .input:"+input, ex);
        }
        return response;
    }
}
